package com.mytijian.exception;

import java.text.MessageFormat;
import java.util.Map;

public abstract class AppException extends RuntimeException {

    private static final long   serialVersionUID = 2488915856414852321L;
    /**
     * 异常编码
     */
    private String              errorCode;
    /**
     * 异常信息
     */
    private String              errorMsg;
    /**
     * 向上层透传的数据
     */
    private Map<String, Object> extInfo;
    
    public AppException() {
        super();
    }
    
    public AppException(String errorCode, String errorInfo) {
        super(errorInfo);
        this.errorMsg = errorInfo;
        this.errorCode = errorCode;
    }

    public AppException(ErrorInfo errorInfo) {
        super(errorInfo.getErrorMsg());
        this.errorMsg = errorInfo.getErrorMsg();
        this.errorCode = errorInfo.getErrorCode();
    }

    public AppException(ErrorInfo errorInfo, Object... params) {
        super(MessageFormat.format(errorInfo.getErrorMsg(), params));
        this.errorMsg = MessageFormat.format(errorInfo.getErrorMsg(), params);
        this.errorCode = errorInfo.getErrorCode();
    }

    public AppException(ErrorInfo errorInfo, Throwable e) {
        super(errorInfo.getErrorMsg(), e);
        this.errorMsg = errorInfo.getErrorMsg();
        this.errorCode = errorInfo.getErrorCode();
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(String errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMsg() {
        return errorMsg;
    }

    public void setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
    }

    public Map<String, Object> getExtInfo() {
        return extInfo;
    }

    public void setExtInfo(Map<String, Object> extInfo) {
        this.extInfo = extInfo;
    }

}
